// components/activity/activity.js
var req = require("../../utils/action.js");
var utils = require("../../utils/util.js");
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    userInfo:{
      type:Map,
      value:{}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  ready:function(){
    console.log("this.properties.data:"+JSON.stringify(this.properties.userInfo))
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getUserInfo:function(e){
      var n = this;
      wx.showLoading({
          mask: !0,
          title: "授权中..."
      });
      var r = this.properties.userInfo, sessionKey = wx.getStorageSync("sessionKey");
      wx.getUserInfp({
          lang: "zh_CN",
          success: function(e) {
              console.log(e, "更新信息");
              if(e.errMsg == 'getUserInfo:ok'){
                let user = e.userInfo
                user.sessionKey = sessionKey
                user.customerId = wx.getStorageSync('customerId')
                n.updateCustomer(user);
              }
              console.log("更新信息")
              //updateCustomer(e);
              wx.hideLoading()
          },
          fail: function(e) {
              console.error(e), wx.hideLoading(), wx.showToast({
                  title: "获取用户信息失败",
                  icon: "none"
              });
          }
      });
    },

    updateCustomer:function(customerData){
      let r = customerData
      let _url = req.actions.ym+"customer/updateCustomer";
      let that = this;
      utils.myResquest(r,_url,function(res){
        if(res.data.code == 200){
          getApp().globalData.userInfo = res.data.content.userInfo
          that.triggerEvent("myevent",{state:'complete'})
        }else{
          that.triggerEvent("myevent",{state:'fail'})
        }
      });
    }
  }
})
